package com.zsrt.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class GsonUtil {
	
	
	public static void  printJson(HttpServletResponse response,Map<String, Object> map) throws IOException{
		//1 设置乱码问题 过滤器
		response.setContentType("application/json; charset=utf-8");  

		//2 得到打印流  JspWriterImpl
		PrintWriter writer =response.getWriter();
		Gson json = new Gson();
		String jsonData = json.toJson(map);

		//3 在流中添加json格式的字符串  Gson
		writer.append(jsonData);

		//4 关闭流
		writer.close();
	}

}
